package com.zmn.oms.task.listener;

import com.alibaba.fastjson.JSON;
import com.zmn.manager.mq.annotation.AliyunMQHandler;
import com.zmn.manager.mq.annotation.AliyunMQListener;
import com.zmn.oms.common.constant.MessageQueueTagConsts;
import com.zmn.oms.model.dto.order.UnavailableServiceDTO;
import com.zmn.oms.zmn.business.interfaces.unavailable.UnAvailableServiceBService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 类描述: 无法承接线索 监听队列
 *
 * @author: liudi
 * @since: 2022/01/18 14:57
 */
@Slf4j
@AliyunMQListener(topic = "${spring.mq.topic.oms}")
@Component
public class UnavailableServiceListener {

    @Autowired
    private UnAvailableServiceBService unAvailableServiceBService;

    /**
     *  保存未成单数据
     *
     * @author liudi
     * @since: 2022/1/18 15:10
     * @param message JSON字符串
     * @return
     */
    @AliyunMQHandler(tags = MessageQueueTagConsts.ORDER_UNAVAILABLE_SERVICE_TAG)
    public void saveUnavailableServiceRecord(String message){
        log.info("#MQ#UnavailableServiceOrderListener#saveUnavailableServiceRecord message:{}", message);
        try {
            UnavailableServiceDTO dto = JSON.parseObject(message, UnavailableServiceDTO.class);
            unAvailableServiceBService.addUnAvailableOrder(dto);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("#MQ#UnavailableServiceOrderListener#saveUnavailableServiceRecord 发生异常：{}", e);
        }
    }
}
